package schedule

import (
	"context"

	"go-caipu/pkg/services/dto"
	"go-caipu/pkg/services/schedule/models"
)

type GetSysJobPageCommand struct {
	dto.Pagination `search:"-"`
	JobName        string `form:"jobName"  search:"type:exact;column:job_name;table:sys_job" comment:"任务名称"`
	Status         int    `form:"status"  search:"type:exact;column:status;table:sys_job" comment:""`
}

type SysJob struct {
	JobId          int    `json:"jobId" gorm:"type:bigint;comment:编号"`
	JobName        string `json:"jobName" gorm:"type:varchar(255);comment:任务名称"`
	JobGroup       int    `json:"jobGroup" gorm:"type:smallint;comment:分组"`
	JobType        int    `json:"jobType" gorm:"type:tinyint;comment:JobType"`
	CronExpression string `json:"cronExpression" gorm:"type:varchar(255);comment:cron表达式"`
	InvokeTarget   string `json:"invokeTarget" gorm:"type:varchar(255);comment:调用目标"`
	Args           string `json:"args" gorm:"type:varchar(255);comment:参当选"`
	MisfirePolicy  int    `json:"misfirePolicy" gorm:"type:bigint;comment:MisfirePolicy"`
	Concurrent     int    `json:"concurrent" gorm:"type:tinyint;comment:Concurrent"`
	Status         int    `json:"status" gorm:"type:tinyint;comment:Status"`
	EntryId        uint   `json:"entryId" gorm:"type:smallint;comment:EntryId"`
	dto.ControlBy
	CreatedAt string `json:"createTime"`
	UpdatedAt string `json:"updatedTime"`
}

func (m *GetSysJobPageCommand) GetNeedSearch() interface{} {
	return *m
}

type GetSysJobCommand struct {
	JobId int `uri:"id"`
}

type RemoveSysJobCommand struct {
	Ids []int `json:"ids"`
}

type GetSysJobLogPageCmd struct {
	dto.Pagination `search:"-"`
	JobId          int      `form:"jobId"  search:"type:exact;column:job_id;table:sys_job_log" comment:"任务编号"`
	JobName        string   `form:"jobName"  search:"type:exact;column:job_name;table:sys_job_log" comment:"任务名称"`
	JobGroup       int      `form:"jobGroup"  search:"type:exact;column:job_group;table:sys_job_log" comment:"任务分组"`
	Status         string   `form:"status"  search:"type:exact;column:status;table:sys_job_log" comment:"状态"`
	DateTimeRange  []string `form:"datetimeRange" search:"-" comment:"日期范围前台接收参数"`
	BeginTime      string   `form:"-" search:"type:gte;column:start_time;table:sys_job_log" comment:"创建时间"`
	EndTime        string   `form:"-" search:"type:lte;column:start_time;table:sys_job_log" comment:"创建时间"`
}

func (m *GetSysJobLogPageCmd) GetNeedSearch() interface{} {
	return *m
}

// Service 业务接口
type Service interface {
	GetSysJobPage(ctx context.Context, cmd GetSysJobPageCommand) (data []SysJob, num int64, err error)
	Get(ctx context.Context, cmd GetSysJobCommand) (SysJob, error)
	Insert(ctx context.Context, cmd SysJob) error
	Update(ctx context.Context, cmd SysJob) error
	Remove(ctx context.Context, cmd RemoveSysJobCommand) error
	InsertJobLog(ctx context.Context, cmd *models.SysJobLog) error
	UpdateJobLog(ctx context.Context, cmd *models.SysJobLog) error
	GetJobLogPage(ctx context.Context, cmd GetSysJobLogPageCmd) (data []models.SysJobLog, num int64, err error)
}
